<template>
  <div id="aCoursesList" class="bg-fa of" style="min-height: 800px" >

    <div class="path-box">
      <!--  nav-->
      <div class="path-wrap txtOf hLh30">
        <a class="c-999 fsize14" href="/">首页</a> /
        <a class="c-999 fsize14" href="/article">学习路径</a> /
        <a class="c-999 fsize14" href="javascript:void(0)">{{path.name }}</a>
      </div>
      <!--  title-->
      <div class="book-info">
        <div class="book-info-box">
          <div class="book-thumb"><img
            :src="path.cover">
          </div>
          <div class="info">
            <div class="book-info-title">{{path.name}}</div>
            <p class="desc">{{path.description}}</p>
            <div class="btn-box"><!---->
              <div class="buy-button" v-if="path.price>0  && !isBuy" @click="toPay()"> 购买套餐￥{{path.price}} <span  v-if="(path.coursesCount || 0)>0">（共{{path.coursesCount || 0}}课程）</span></div>
              <div class="has-button" v-else-if="path.price>0 && isBuy">已购买</div>
              <div class="has-button" v-else>本路径免费</div>
              <div class="original">原价:￥{{path.originalPrice}}</div>
            </div>
          </div>
        </div>
      </div>

      <!--步骤 课程-->
      <div class="book-chapter-box"  >
        <div class="steps-box">
          <!--学习步骤-->
          <template v-if="stepList.length">
            <div class="step-item" v-for="(item,index) in stepList" :key="index">
              <div class="left-item">
                <img
                  style="display: none" :style="loading?'':'display:block'"
                  src=""
                class="icon">
                <div class="column"></div>
              </div>
              <div class="right-item">
                <div class="step-title"> {{item.name}}</div>
                <div class="step-desc">
                  {{item.description}}
                </div>
                <div scroll-x="true" class="courses-box" >
                  <!--关联课程-->
                  <div v-if="!item.relationList.length"  style="display: none" :style="loading?'':'display:block'" >
                      <span class="c-999 fsize14 ml10 vam">没有相关数据</span>
                  </div>
                  <template v-if="item.relationList.length">
                    <div class="course-item" v-for="(course,index) in item.relationList" :key="index" @click="goCourseInfo(course.targetType,course.targetId)">
                      <div class="course-thumb" >
                        <div class="spback"></div>
                        <div class="thumb-bar">
                          <div class="box">
                            <div
                              :style="{'background-image': 'url('+course.cover+')'}"
                              style="width: 133px; height: 75px;  background-size: contain; background-repeat: no-repeat;"></div>
                          </div>
                        </div>
                      </div>
                      <div class="course-body">
                        <div class="course-name">{{course.name}}</div>
                        <div class="course-type"> {{$enum.getDescByValue('COURSE_TYPE',course.targetType) }}</div>
                        <div class="course-charge"> 原价:￥{{course.charge}}</div>
                      </div>
                    </div>
                  </template>
                  <template>

                  </template>
                </div>


              </div>
            </div>
          </template>
          <!-- 无数据提示-->
          <template v-else>
            <section class="no-data-wrap">
              <em class="icon30 no-data-ico">&nbsp;</em>
              <span class="c-666 fsize14 ml10 vam">没有相关数据</span>
            </section>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import pathApi from '@/api/pathApi'
  import order from '@/api/order'

  export default {
    data() {
      return {
        pathId: this.$route.params.id,
        path: {},
        stepList: [
          {
            stepId: '',
            relationList: []
          }
        ],
        relationList: {},
        loading:true,
        isBuy:false
      }
    }, created() {
      this.getData()
    }, methods: {
      getData() {
        pathApi.getById(this.pathId).then(resp => {
          this.path = resp.path
          this.stepList = resp.step
          this.isBuy = resp.isBuy

          this.stepList.forEach(step => {
            step.relationList = (resp.relation || []).filter(x => x.stepId == step.id)
          })
          console.log('stepList', this.stepList)
          setTimeout(() => (this.loading = false), 400)
        }).catch(err=>{
          this.loading = false
        })
      },
      goCourseInfo(type,id){
        let toInfo = this.$router.resolve({path: `/${this.$enum.getObjByValue('COURSE_TYPE', type).path}/` + id})
        window.open(toInfo.href, '_blank')
      },
      toPay(){
        order.createOrder(this.$enum.COURSE_TYPE.PATH.value,this.pathId).then(response => {
          console.log(response)
          if (response) {
            //订单创建成功，跳转到订单页面
            this.$router.push({path: `/order/${response}` })
          }
        })
      }
    }
  }
</script>
<style>
  [v-cloak] {
    display: none !important;
  }
  .path-box {
    width: 1200px;
    margin: 0 auto;
  }

  .book-info {
    width: 1200px;
    height: 300px;
    background: #fff;
    border-radius: 8px;
  }

  .book-info .book-info-box {
    width: 1200px;
    height: 300px;
    box-sizing: border-box;
    padding: 30px 50px 30px 30px;
    position: relative;
    display: flex;
    flex-direction: row;
  }

  .book-info .book-info-box .book-thumb {
    width: 320px;
    height: 240px;
    border-radius: 8px;
    margin-right: 50px;
    position: relative;
  }

  .book-info .book-info-box .book-thumb img {
    width: 320px;
    height: 240px;
    border-radius: 8px;
  }

  .book-info .book-info-box .info {
    width: 750px;
    height: 240px;
    position: relative;
  }

  .book-info .book-info-box .info .book-info-title {
    width: 710px;
    height: 30px;
    font-size: 24px;
    font-weight: 500;
    color: #333;
    line-height: 24px;
    margin-top: 20px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .book-info .book-info-box .info .desc {
    margin-top: 14px;
    width: 750px;
    height: 90px;
    font-size: 16px;
    font-weight: 400;
    color: #666;
    line-height: 30px;
    overflow: hidden;
  }

  .book-info .book-info-box .info .btn-box {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    float: left;
    display: flex;
    flex-direction: row;
  }

  .book-info .book-info-box .info .btn-box .buy-button {
    background: #ff5068;
    border-radius: 4px;
    padding: 20px;
    font-size: 16px;
    font-weight: 400;
    color: #fff;
    line-height: 16px;
    box-sizing: border-box;
    cursor: pointer;
  }

  .book-info .book-info-box .info .btn-box .original {
    padding: 20px 0;
    font-size: 16px;
    font-weight: 400;
    color: #999;
    line-height: 16px;
    box-sizing: border-box;
    text-decoration: line-through;
    margin-left: 30px;
  }

  /*  列表*/
  .book-chapter-box {
    width: 1200px;
    padding: 50px 30px;
    background: #fff;
    margin-top: 30px;
    border-radius: 8px;
  }

  .book-chapter-box .steps-box {
    width: 100%;
    height: auto;
  }

  .book-chapter-box .steps-box .step-item {
    width: 100%;
    height: auto;
    display: flex;
    flex-direction: row;
  }

  .book-chapter-box .steps-box .step-item:not(:last-child) {
    margin-bottom: 50px;
  }

  .book-chapter-box .steps-box .step-item .left-item {
    width: 20px;
    height: auto;
    float: left;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .book-chapter-box .steps-box .step-item .left-item .icon {
    width: 20px;
    height: 20px;
  }

  .book-chapter-box .steps-box .step-item .left-item .column {
    width: 1px;
    height: 100%;
    flex: 1;
    margin-top: 10px;
    background: #e5e5e5;
  }

  .book-chapter-box .steps-box .step-item .right-item {
    width: 1090px;
    height: auto;
    float: left;
    margin-left: 30px;
  }

  .book-chapter-box .steps-box .step-item .right-item .step-desc {
    width: 100%;
    height: auto;
    max-height: 56px;
    font-size: 16px;
    font-weight: 400;
    color: #333;
    line-height: 28px;
    overflow: hidden;
    margin-bottom: 30px;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box {
    width: 100%;
    height: auto;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box .course-item {
    width: 100%;
    height: 100px;
    display: flex;
    flex-direction: row;
    align-items: center;
    position: relative;
    cursor: pointer;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box .course-item:not(:last-child) {
    margin-bottom: 30px;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box .course-item .course-thumb {
    width: 133px;
    height: 75px;
    background: #f0f0f8;
    border-radius: 4px;
    margin-right: 30px;
    display: flex;
    justify-content: center;
    overflow: hidden;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box .course-item .course-thumb .spback {
    position: absolute;
    left: 20px;
    top: 10px;
    width: 93px;
    height: 80px;
    background: #d2e1ef;
    border-radius: 8px;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box .course-item .course-thumb .thumb-bar {
    width: 100%;
    height: 100%;
    z-index: 10;
    border-radius: 4px;
    overflow: hidden;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box .course-item .course-body {
    width: 927px;
    height: 100px;
    display: flex;
    flex-direction: column;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box .course-item .course-body .course-name {
    width: 100%;
    height: 14px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    line-height: 14px;
    margin-top: 10px;
    margin-bottom: 15px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box .course-item .course-body .course-type {
    width: 56px;
    height: 22px;
    background: #04c877;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 400;
    color: #fff;
    margin-bottom: 18px;
  }

  .book-chapter-box .steps-box .step-item .right-item .courses-box .course-item .course-body .course-charge {
    height: 14px;
    font-size: 14px;
    font-weight: 500;
    color: #999;
    line-height: 14px;
  }

  .content .box {
    width: 1200px;
    margin: 0 auto;
  }
</style>
